﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.lishun;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;
using System;

namespace SheepStorage.API.Application.CommandHandlers.SheepRecordHandlers
{
    public class AddSheepRecordCommandHandler : IRequestHandler<AddSheepRecordCommand, Results<int>>
    {
        ISheepRecordService _service;
        IMapper _mapper;
        public AddSheepRecordCommandHandler(ISheepRecordService service, IMapper mapper)
        {
            _service = service;
            _mapper = mapper;
        }
        public async Task<Results<int>> Handle(AddSheepRecordCommand request, CancellationToken cancellationToken)
        {

            var list = new SheepRecord
            {
                OverBit = request.OverBit,
                ElEarTag = request.ElEarTag,
                SheepRecordVariety = request.SheepRecordVariety,
                SheepRecordSex = request.SheepRecordSex,
                SheepRecordBirthDate = request.SheepRecordBirthDate,
                SheepRecordDay = request.SheepRecordDay,
                SheepRecordMoom = request.SheepRecordMoom,
                SheepRecordGrowth = request.SheepRecordGrowth,
                BuildingName = request.BuildingName,
                SheepFieldName = request.SheepFieldName,
                SheepRecordType = request.SheepRecordType,
                SheepRecordGene = request.SheepRecordGene,
                SheepRecordProduction = request.SheepRecordProduction,
                SheepRecordMarket = request.SheepRecordMarket,
                SheepRecordBreedState = request.SheepRecordBreedState,
                SheepRecordBreedDay = request.SheepRecordBreedDay,
                SheepRecordDadOverbit = request.SheepRecordDadOverbit,
                SheepRecordMomOverbit = request.SheepRecordMomOverbit,
                SheepRecordPresentState = request.SheepRecordPresentState,
                SheepRecordGestation = request.SheepRecordGestation,
                SheepRecordWeightBirth = request.SheepRecordWeightBirth,
                SheepRecordWeaningWeight = request.SheepRecordWeaningWeight,
                SheepRecordWeaningDate = request.SheepRecordWeaningDate,
                SheepRecordWeaningAge = request.SheepRecordWeaningAge,
                SheepRecordRemark = request.SheepRecordRemark,
            };
            var lists =await  _service.AddSheepRecord(list);
            return Results<int>.DataResult(lists);
        }
    }
}
